﻿using Basic.OAGatewayModule.ExtendService.Interface;
using Basic.OAGatewayModule.Interface;
using Basic.OAGatewayModule.Model.FillIn;
using Basic.OARemoteModel.DataFillIn;
using Basic.OARemoteModel.DataFillIn.Model;
using WeDonekRpc.Client;
using WeDonekRpc.HttpApiGateway.Model;

namespace Basic.OAGatewayModule.lmpl
{
    internal class DataFillInService : IDataFillInService
    {
        private readonly IEmpService _Emp;

        public DataFillInService ( IEmpService emp )
        {
            this._Emp = emp;
        }

        public long Add ( FillInAddDto data, long userId )
        {
            FillInAdd add = data.ConvertMap<FillInAddDto, FillInAdd>();
            add.CreateEmpId = userId;
            return new AddFillIn
            {
                Datum = add
            }.Send();
        }
        public bool Set ( long id, FillInSet data )
        {
            return new SetFillIn
            {
                Id = id,
                Datum = data
            }.Send();
        }
        public void Delete ( long id )
        {
            new DeleteFillIn
            {
                Id = id
            }.Send();
        }
        public FillInDto Get ( long id )
        {
            FillInData data = new GetFillIn
            {
                Id = id
            }.Send();
            FillInDto dto = data.ConvertMap<FillInData, FillInDto>();
            dto.PublicEmp = this._Emp.GetName(dto.CreateEmpId);
            return dto;

        }
        public PagingResult<FillInDatum> Query ( PagingParam<FillInQuery> param )
        {
            return new QueryFillIn
            {
                NextId = param.NextId,
                Size = param.Size,
                SortName = param.SortName,
                Index = param.Index,
                IsDesc = param.IsDesc,
                Query = param.Query
            }.Send();
        }

        public void Stop ( long id )
        {
            new StopFillIn
            {
                Id = id
            }.Send();
        }
    }
}
